using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class LbsChoosePage : BasePage, FMsgChange
	{
		private const string TAG = "LbsChoosePage";
		private object[] passData;
		public FMessageValidInfo FNewestMsg;
		private EventWatcher mWatcherHeadImgAdd;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal ClickableLayout newMsgTipsLayout;
		internal StackPanel newMsgTipsContentLayout;
		internal Image newMsgHead;
		internal TextBlock newMsgNumber;
		internal Button btnStart;
		private bool _contentLoaded;
		public LbsChoosePage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("LbsChoosePage", "OnPageIn");
			this.passData = object_0;
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("LbsChoosePage", "OnPageOut");
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("LbsChoosePage", "OnPageBack");
			this.showNewMsgTipsLayoutIfNeed();
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("LbsChoosePage", "Page_Loaded");
			this.initEventWatcher();
			this.showNewMsgTipsLayoutIfNeed();
			FMsgMgr.addObserver(this);
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("LbsChoosePage", "Page_Unloaded");
			FMsgMgr.removeObserver(this);
			this.unInitEventWatcher();
			this.FNewestMsg = null;
		}
		private void initEventWatcher()
		{
			if (this.mWatcherHeadImgAdd == null)
			{
				this.mWatcherHeadImgAdd = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerHeadImgAdd));
			}
			EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
		}
		private void unInitEventWatcher()
		{
			if (this.mWatcherHeadImgAdd != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
				this.mWatcherHeadImgAdd = null;
			}
		}
		private void onEventHandlerHeadImgAdd(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<string> listObject = evtArgs.getListObject<string>();
			if (listObject == null)
			{
				return;
			}
			using (List<string>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null && current.GetType() == typeof(string) && this.FNewestMsg != null && this.FNewestMsg.UserName == current)
					{
						this.updateNewMsgImg();
						break;
					}
				}
			}
		}
		public void onFMsgNewNumChange(FMsgType type)
		{
		}
		public void onFMsgDel(ChatMsg chatMsg_0, FMsgType type)
		{
		}
		public void onFMsgAdd(ChatMsg chatMsg_0, FMsgType type)
		{
			if (type != FMsgType.const_0)
			{
				return;
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.showNewMsgTipsLayoutIfNeed();
			});
		}
		private void updateNewMsgImg()
		{
			ImageSource imageSource = null;
			if (this.FNewestMsg != null)
			{
				imageSource = HeadImgMgr.getHeadImage(this.FNewestMsg.UserName, true);
			}
			if (imageSource == null)
			{
				imageSource = HeadImgMgr.defaultHeadImage;
			}
			this.newMsgHead.set_Source(imageSource);
		}
		private void showNewMsgTipsLayoutIfNeed()
		{
			int newMsgNum = FMsgMgr.getNewMsgNum(FMsgType.const_0);
			if (newMsgNum > 0)
			{
				int num = (newMsgNum > 99) ? 99 : newMsgNum;
				string text = string.Format(strings.Shake_SayHello_Num, num);
				this.newMsgNumber.set_Text(text);
				List<ChatMsg> msgList = FMsgMgr.getMsgList(FMsgType.const_0, 0, 1, false);
				if (msgList != null && msgList.get_Count() == 1)
				{
					this.recordNewestSayHelloMsg(msgList.get_Item(0));
				}
				this.newMsgTipsLayout.set_Visibility(0);
				return;
			}
			this.newMsgTipsLayout.set_Visibility(1);
		}
		private void hideNewMsgTipsLayout()
		{
			this.newMsgTipsLayout.set_Visibility(1);
		}
		private void recordNewestSayHelloMsg(ChatMsg chatMsg_0)
		{
			if (chatMsg_0 == null)
			{
				return;
			}
			this.FNewestMsg = FMessageHelper.GetFmessageValidInfo(chatMsg_0);
			this.updateNewMsgImg();
		}
		private void newMsgTipsLayout_Click(object sender, object object_0)
		{
			base.GoToPage("/Source/Plugin/Lbs/UI/SayHelloPage.xaml", null, false);
			this.hideNewMsgTipsLayout();
		}
		private void btnStart_Click(object sender, RoutedEventArgs e)
		{
			base.GoToPage("/Source/Plugin/Lbs/UI/LbsPeopleList.xaml", this.passData, true);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Lbs/UI/LbsChoosePage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.newMsgTipsLayout = (ClickableLayout)base.FindName("newMsgTipsLayout");
			this.newMsgTipsContentLayout = (StackPanel)base.FindName("newMsgTipsContentLayout");
			this.newMsgHead = (Image)base.FindName("newMsgHead");
			this.newMsgNumber = (TextBlock)base.FindName("newMsgNumber");
			this.btnStart = (Button)base.FindName("btnStart");
		}
	}
}
